package top.birdhk.TestAPI.transorm;

import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import top.birdhk.TestAPI.beans.SensorReading;

public class TransformPartition {

    public static void main(String[] args) throws Exception {


        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<String> inputSream = env.readTextFile("E:\\flink\\wordcount\\src\\main\\resources\\sensor.txt");

//        env.setParallelism(1);
//
        SingleOutputStreamOperator<SensorReading> dataStream = inputSream.map(line -> {
            String[] split = line.split(",");
            return new SensorReading(split[0], new Long(split[1]), new Double(split[2]));
        });

//        inputSream.print("input");


        // shuffle
        DataStream<String> shuffle = inputSream.shuffle();

        shuffle.print();

        // keyby
        dataStream.keyBy("id").print();

        // golbal
        dataStream.global().print();



        env.execute();


    }

}
